import React,{Component} from 'react';
import { AsyncStorage, View, Text } from 'react-native';


class NewsPage extends Component{

    constructor(){
        super();
        this.state={
            title:'1',
            content:'2',
        }
    }

    // render之后执行的周期
    componentDidMount(){
        AsyncStorage.getItem('hd',(err,x)=>{
            alert(x+'1111111');
        })
    }


    // 在render之前请求文章数据
    componentWillMount(){
        let aid = this.props.navigation.state.params.aid;
        // 发请求
        fetch('http://47.100.185.180/api/article.php?aid='+aid).then(x => {
            // console.log(JSON.parse(x._bodyInit).content);
            // 设置标题和内容
            this.setState({
                title:JSON.parse(x._bodyInit).title,
                content:JSON.parse(x._bodyInit).content,
            })

        })
    }

    render() {

        return (
            <View>
                <Text style={{fontSize:25}}>{this.state.title}</Text>
                <Text style={{fontSize:25}}>{this.state.content}</Text>
            </View>
        )
    }
}

export default NewsPage;

